<?php
namespace app\model\SysAccount;
use app\model\BaseModel;
use app\utils\CamlHump;
use think\facade\Db;
class SysRoleFun extends BaseModel
{
    protected $convertNameToCamel = true;
    protected $name = 'sys_role_fun';

    static function  build($data)
    {
        $emptyData = [];

             $emptyData['id']= $data['id' ] ?? null;




             $emptyData['appId']= $data['appId' ] ?? 0;




             $emptyData['consuFunId']= $data['consuFunId' ] ?? 0;




             $emptyData['roleId']= $data['roleId' ] ?? 0;




             $emptyData['funId']= $data['funId' ] ?? 0;




             $emptyData['funParentId']= $data['funParentId' ] ?? 0;




             $emptyData['funDeep']= $data['funDeep' ] ?? 0;




             $emptyData['tenantType']= $data['tenantType' ] ?? 0;




             $emptyData['tenantId']= $data['tenantId' ] ?? 0;




             $emptyData['delState']= $data['delState' ] ?? 0;





          //是 VARCHAR 类型的 VARCHAR
                $emptyData['addUser']= $data['addUser' ] ?? '';



             $emptyData['addUserId']= $data['addUserId' ] ?? 0;






          //是 VARCHAR 类型的 DATETIME
              $emptyData['addTime']= $data['addTime' ] ?? date("Y-m-d H:i:s", time());



          //是 VARCHAR 类型的 VARCHAR
                $emptyData['editUser']= $data['editUser' ] ?? '';



             $emptyData['editUserId']= $data['editUserId' ] ?? 0;






          //是 VARCHAR 类型的 DATETIME
              $emptyData['lastEditTime']= $data['lastEditTime' ] ?? date("Y-m-d H:i:s", time());


             $emptyData['serverNumber']= $data['serverNumber' ] ?? 0;



        return $emptyData;
    }
    static function createQuery($queryData)
    {
       $query = Db::table('sys_role_fun');

           //是int类型的 BIGINT
                if(isset($queryData['id'])&&$queryData['id']>0){
                    $query->where('id', $queryData['id']);
                }



           //是int类型的 BIGINT
                if(isset($queryData['appId'])&&$queryData['appId']>0){
                    $query->where('app_id', $queryData['appId']);
                }



           //是int类型的 BIGINT
                if(isset($queryData['consuFunId'])&&$queryData['consuFunId']>0){
                    $query->where('consu_fun_id', $queryData['consuFunId']);
                }



           //是int类型的 BIGINT
                if(isset($queryData['roleId'])&&$queryData['roleId']>0){
                    $query->where('role_id', $queryData['roleId']);
                }



           //是int类型的 BIGINT
                if(isset($queryData['funId'])&&$queryData['funId']>0){
                    $query->where('fun_id', $queryData['funId']);
                }



           //是int类型的 BIGINT
                if(isset($queryData['funParentId'])&&$queryData['funParentId']>0){
                    $query->where('fun_parent_id', $queryData['funParentId']);
                }



           //是int类型的 SMALLINT
                if(isset($queryData['funDeep'])&&$queryData['funDeep']>0){
                    $query->where('fun_deep', $queryData['funDeep']);
                }



           //是int类型的 TINYINT
                if(isset($queryData['tenantType'])&&$queryData['tenantType']>0){
                    $query->where('tenant_type', $queryData['tenantType']);
                }



           //是int类型的 BIGINT
                if(isset($queryData['tenantId'])&&$queryData['tenantId']>0){
                    $query->where('tenant_id', $queryData['tenantId']);
                }



           //是int类型的 TINYINT
                if(isset($queryData['delState'])&&$queryData['delState']>0){
                    $query->where('del_state', $queryData['delState']);
                }



              //是 VARCHAR 类型的 VARCHAR
                if(isset($queryData['addUser'])&&$queryData['addUser']!=''){
                    $query->where('add_user', $queryData['addUser']);
                }


           //是int类型的 BIGINT
                if(isset($queryData['addUserId'])&&$queryData['addUserId']>0){
                    $query->where('add_user_id', $queryData['addUserId']);
                }




              //是 VARCHAR 类型的 DATETIME
                if(isset($queryData['addTime'])&&$queryData['addTime']!=''){
                    $query->where('add_time', $queryData['addTime']);
                }


              //是 VARCHAR 类型的 VARCHAR
                if(isset($queryData['editUser'])&&$queryData['editUser']!=''){
                    $query->where('edit_user', $queryData['editUser']);
                }


           //是int类型的 BIGINT
                if(isset($queryData['editUserId'])&&$queryData['editUserId']>0){
                    $query->where('edit_user_id', $queryData['editUserId']);
                }




              //是 VARCHAR 类型的 DATETIME
                if(isset($queryData['lastEditTime'])&&$queryData['lastEditTime']!=''){
                    $query->where('last_edit_time', $queryData['lastEditTime']);
                }

           //是int类型的 SMALLINT
                if(isset($queryData['serverNumber'])&&$queryData['serverNumber']>0){
                    $query->where('server_number', $queryData['serverNumber']);
                }



         $query->where('del_state', 1);

      return   $query;

    }
 static function addPlus($data){
        $addWidthDefault = static::build($data);
        $result = static::create($addWidthDefault);
        return $result;
    }
    static function updatePlus($data, $id)
    {
        $result = static::update($data, ['id' => $id]);
        return $result;
    }
static function deletePlus($id)
    {
        $result = static::destroy($id);
        return $result;
    }

    static function findOne($id){
        $query=Db::table('sys_role_fun')->where("id", $id);
        $one = CamlHump::toCamlObj($query->find());
        return $one;
    }

    static function exitOne($query){
        return $query->count()>0;
    }

}